package unseen.games.utils;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class ConnectivityUtils {
	
	private static final int TYPE_MOBILE 	= ConnectivityManager.TYPE_MOBILE;
	private static final int TYPE_WIFI 		= ConnectivityManager.TYPE_WIFI;

	private ConnectivityManager mManager;
	private Context mContext;

	public ConnectivityUtils(Context context){
		mContext = context;
		mManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	}
	

	public int getNetworkPreference(){
		return mManager.getNetworkPreference();
	}

	public boolean isWifiAvailable(){
		return mManager.getNetworkInfo(TYPE_WIFI).isAvailable();
	}
	
	public boolean isWifiConnected(){
		return mManager.getNetworkInfo(TYPE_WIFI).isConnected();
	}
	
	public boolean isWifiConnecting(){
		NetworkInfo info = mManager.getNetworkInfo(TYPE_WIFI);
		return (info.isConnectedOrConnecting() && !info.isConnected());
	}
	
	public boolean isMobileAvailable(){
		return mManager.getNetworkInfo(TYPE_MOBILE).isAvailable();
	}
	
	public boolean isMobileConnected(){
		return mManager.getNetworkInfo(TYPE_MOBILE).isConnected();
	}
	
	public boolean isMobileConnecting(){
		NetworkInfo info = mManager.getNetworkInfo(TYPE_MOBILE);
		return (info.isConnectedOrConnecting() && !info.isConnected());
	}
	
	public boolean isConnected(){
		return isMobileConnected() || isWifiConnected();
	}
	
	public void pickWifiNetwork(){
		mContext.startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK));
	}
	
}
	
	
	

